package org.dream.service;

import java.util.List;

import org.dream.domain.Daydeal;

/**
 * 
 * <p>
 * Title:
 * </p>
 * <p>
 * Description:
 * </p>
 * <p>
 * Copyright: Copyright (c) 2009
 * </p>
 * <p>
 * Company: cattsoft
 * </p>
 * 
 * @author 关攀攀
 */
public class HLYService {
	/**
	 * 计算价量关系
	 */
	public int countJlScore(List<Daydeal> daydeals) {
		int score = 0;
		Daydeal preDaydeal = null;
		for (Daydeal daydeal : daydeals) {
			if (preDaydeal != null) {
				/*
				 * double zhangFu = (daydeal.getShouPan() - preDaydeal
				 * .getShouPan()) / preDaydeal.getShouPan() * 100; zhangFu =
				 * DoubleUtil.changeDecimal(zhangFu, 2);
				 * daydeal.setZhangFu(zhangFu);
				 */
				setJlScore(preDaydeal, daydeal);

			} else {
				daydeal.setJlScore(0);
			}
			score += daydeal.getJlScore();
			daydeal.setJlScoreTotal(score);
			preDaydeal = daydeal;

		}
		return score;

	}

	private void setJlScore(Daydeal preDaydeal, Daydeal daydeal) {
		// 价涨
		if ((daydeal.getCLOSE() - preDaydeal.getCLOSE()) > 0.01) {
			// 量增
			if ((daydeal.getVOL() - preDaydeal.getVOL()) > 0.0001) {
				daydeal.setJlScore(2);
			} else {
				daydeal.setJlScore(1);
			}
		} else if ((daydeal.getCLOSE() - preDaydeal.getCLOSE()) < -0.01) {
			// 量增
			if (daydeal.getVOL() > preDaydeal.getVOL()) {
				daydeal.setJlScore(-2);
			} else {
				daydeal.setJlScore(-1);
			}
		} else {
			daydeal.setJlScore(0);
		}
	}
}
